package com.imooc.mall.util;

import com.imooc.mall.common.Constant;
import org.apache.tomcat.util.codec.binary.Base64;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/*
*  加密算法
* */
public class MD5Utils {
    public static String getMD5str(String strValue) throws NoSuchAlgorithmException {
        //1.1 java自带jar工具MessageDigest实现
//       return Base64.encodeBase64String(MessageDigest.getInstance("MD5").digest(strValue.getBytes()));

        MessageDigest md5 = MessageDigest.getInstance("MD5");
        return Base64.encodeBase64String(md5.digest((strValue+ Constant.SALT).getBytes()));
    }

    public static void main(String[] args) {
        String md5 = null;
        try {
            md5 = getMD5str("1234");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        System.out.println(md5);
    }
}


